package main.Q2401_2500;

import java.util.Stack;

public class Q2481_2490 {
    public static void main(String[] args) {
        System.out.println("Question2481：");
        System.out.println("Question2482：行和列中一和零的差值");
        System.out.println("Question2483：");
        System.out.println("Question2484：");
        System.out.println("Question2485：");
        System.out.println("Question2486：");
        System.out.println("Question2487：从链表中移除节点");
        System.out.println("Question2488：");
        System.out.println("Question2489：");
        System.out.println("Question2490：");
    }
}

class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}

class Question2482{
    public int[][] onesMinusZeros(int[][] grid) {
        int n = grid.length, m = grid[0].length;
        int[] row = new int[n];
        int[] col = new int[m];
        for (int i = 0 ; i < n; i++) {
            for (int j = 0; j < m; j++) if (grid[i][j] == 1) {row[i]++; col[j]++;}
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                grid[i][j] = 2 * row[i] + 2 * col[j] - m - n;
            }
        }
        return grid;
    }
}

class Question2487 {
    public ListNode removeNodes(ListNode head) {
        Stack<Integer> stack = new Stack<>();
        while (head != null) {
            if (stack.isEmpty() || stack.peek() > head.val) {
                stack.add(head.val);
            } else {
                while (!stack.isEmpty() && stack.peek() < head.val) {
                    stack.pop();
                }
                stack.add(head.val);
            }
            head = head.next;
        }
        ListNode result = null;
        while (!stack.isEmpty()) {
            ListNode temp = new ListNode(stack.pop());
            temp.next = result;
            result = temp;
        }
        return result;
    }
}
